import  requests

class HtmlDownloader:

    def download(self, url):
        # 判断URL是否为空
        if url is None:
            return None
        else:
            print("开始下载数据，网址{0}".format(url))
            response = requests.get(url)
            # 如果请求成功，则返回网页数据，否则返回None
            if response.status_code == 200:
                print("下载数据成功")
                # 指定使用UTF-8编码
                response.encoding = 'utf-8'
                return response.text
            else:
                return None


if __name__ == "__main__":
    url = 'http://www.bing.com/'
    d = HtmlDownloader()
    bing_html = d.download(url)
    print(bing_html)

"""
下载器功能很简单，只需使用requests中的get功能进行网页下载即可。在数据返回时需要判断是否下载成功，
即，判断响应码是否为200.
"""
